package com.aidong.liveVideo.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.aidong.liveVideo.biz.TrnLiveVideoBiz;
import com.aidong.liveVideo.entity.TrnLiveVideoPraise;
import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("json")
@Namespace("/")
public class TrnTrnVideoPraiseAction implements ModelDriven<TrnLiveVideoPraise> {
	private TrnLiveVideoPraise trnLiveVideoPraise;
	
	@Override
	public TrnLiveVideoPraise getModel() {
		if (trnLiveVideoPraise == null) {
			trnLiveVideoPraise = new TrnLiveVideoPraise();
		}
		return trnLiveVideoPraise;
	}
	private Map<String, Object> map;

	@JSON
	public Map<String, Object> getMap() {
		return map;
	}
	private TrnLiveVideoBiz trnLiveVideoBiz; 
	@Autowired
	public void setTrnLiveVideoBiz(TrnLiveVideoBiz trnLiveVideoBiz) {
		this.trnLiveVideoBiz = trnLiveVideoBiz;
	} 
	
	@Action(value = "addLiveVideoPraise", results = { @Result(name = "succ", type = "json", params = { "root", "map" }) })
	public String addLiveVideoPraise() {
		map = new HashMap<String, Object>();
		
		if(trnLiveVideoPraise.getLiveId() >0 && trnLiveVideoPraise.getIdongId() > 0){
			try{
				
				trnLiveVideoPraise.setPraiseStatus(0);
				trnLiveVideoBiz.addLiveVideoPraise(trnLiveVideoPraise);
				map.put("result", "已点赞");
				map.put("code", 1);
				
				return "succ";
			} catch(Exception e) {
				map.put("code", 0);
				map.put("msg", "系统异常");
				return "succ";
			}
		}else{
			map.put("code", 0);
			map.put("msg", "参数缺失");
			return "succ";
		}
	}
	
}
